package com.weihui.jxc.view;

import java.awt.EventQueue;

import java.awt.Toolkit;

import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

import com.weihui.jxc.common.ValidationManager;
import com.weihui.jxc.view.goods.GoodsEditPanel;
import com.weihui.jxc.view.goods.GoodsAddPanel;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.FlowLayout;
import java.awt.Color;
/**
 * 商品信息管理界面（添加、修改、删除）
 * @author xiaowei
 *
 */
public class GoodsInternalFrame extends JInternalFrame {


	/**
	 * Create the frame.
	 */
	public GoodsInternalFrame() {
		setTitle("商品信息管理");
		setIconifiable(true);//支持窗口最小化显示
		setClosable(true);//支持窗口可关闭
		getContentPane().setLayout(new BorderLayout(0, 0));
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		setBounds(screenSize.width/12,screenSize.height/20,screenSize.width/2,screenSize.height/2);
        //创建选项卡
		JTabbedPane tabPane = new JTabbedPane();
		final GoodsAddPanel addPanel = new GoodsAddPanel();//商品信息添加面板
		final GoodsEditPanel editPanel = new GoodsEditPanel();//商品信息编辑面板
		//向选项卡添加面板
		tabPane.addTab("商品信息添加",null,addPanel,"商品信息添加");
		//addPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		tabPane.addTab("商品信息编辑", null,editPanel,"商品信息编辑");
		//editPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		//向Frame窗口添加选项卡
		getContentPane().add(tabPane);
		//给选项卡设置改变监听
		tabPane.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
			    //初始化 编辑界面的下拉列表框
				editPanel.initGoodsComboBox();
				editPanel.initProviderComboBox();
			}
		});
		//在商品管理窗口被激活时，初始化商品添加界面的供应商下拉选择框。
		addInternalFrameListener(new InternalFrameAdapter() {
			@Override
			public void internalFrameActivated(InternalFrameEvent e) {
				addPanel.initComboBox();
			}
		});
		pack();//通过内部组件自动设置窗口大小
		setVisible(true);//显示窗口

	}
	/**
	 * 数据格式校验
	 */
	public static Boolean dataCheck(String name,String shorts,String place,String sizes,String packages,
			String productCode,String pCode,String price,String memo,String provider) {
		Boolean isTrue=true;

		if(isTrue) {
				if(name.equals("")||
				shorts.equals("")||
				place.equals("")||
				sizes.equals("")||
				packages.equals("")||
				productCode.equals("")||
				pCode.equals("")||
			    price.equals("")||
				memo.equals("")||
				provider.equals("")) {
			JOptionPane.showMessageDialog(null, "请填写全部信息！","温馨提示",JOptionPane.INFORMATION_MESSAGE);
			 isTrue=false;
			return isTrue;
		}
		if(!ValidationManager.validatePrice(price)) {
			JOptionPane.showMessageDialog(null, "价格输入不合法！","警告",JOptionPane.WARNING_MESSAGE);
			isTrue=false;
			return isTrue;
		}
		}
		return isTrue;
		
	
	}


}